package com.aoip.telemetry.telemetry.configureui.business.commonconfig.factorystation.service.impl;

import com.aoip.telemetry.telemetry.configureui.business.commonconfig.factorystation.entity.FactoryStationBaseEntity;
import com.aoip.telemetry.telemetry.configureui.business.commonconfig.factorystation.mapper.FactorystationBaseMapper;
import com.aoip.telemetry.telemetry.configureui.business.commonconfig.factorystation.service.FactoryStationBaseService;
import com.aoip.telemetry.telemetry.core.redis.RedisCache;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * @author chenbai
 * @version 1.0
 * @date 2022/4/23 14:52
 */
@Service
@DS("telemetry")
public class FactoryStationBaseServiceImpl implements FactoryStationBaseService {

    @Resource
    private FactorystationBaseMapper mapper;
    @Resource
    private RedisCache redisCache;

    @Override
    public List<FactoryStationBaseEntity> list(FactoryStationBaseEntity entity) {
        QueryWrapper<FactoryStationBaseEntity> queryWrapper = new QueryWrapper<>();
        String factoryStationName = entity.getFactoryStationName();
        if (StringUtils.hasText(factoryStationName)) {
            queryWrapper.like(true, "factory_station_name", factoryStationName);
        }
        String factoryStationType = entity.getFactoryStationType();
        if (StringUtils.hasText(factoryStationType)) {
            queryWrapper.eq(true, "factory_station_type", factoryStationType);
        }
        return mapper.selectList(queryWrapper);
    }

    @Override
    public FactoryStationBaseEntity detail(String id) {
        return mapper.selectById(id);
    }

    @Override
    public int insert(FactoryStationBaseEntity entity) {
        return mapper.insert(entity);
    }

    @Override
    public int update(FactoryStationBaseEntity entity) {
        return mapper.updateById(entity);
    }

    @Override
    public int initCache() {
        return 0;
    }

    @Override
    public void delete(Long[] ids) {
        mapper.deleteBatchIds(Arrays.asList(ids));
    }
}
